<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
		<link rel="stylesheet" href="js/Cesium/Widgets/widgets.css" />
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
		<script src="js/Cesium/Cesium.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
		<style>
			html,body{
				margin: 0;
				padding: 0;
				height: 100%;
				width: 100%;
			}
			#contanter{
				width:100%;
				height:100%
			}    
			/* 去除logo信息 */	
			.cesium-widget-credits{ 
				display:none!important; 
				visibility:hide!important; 
			} 
			
			/* 添加点、线、面的按钮*/
			.addEntities{
				position: fixed;
				left: 110px;
				top: 10px;
				z-index: 99999;
			}
			button{
				background-color: rgba(47,53,60,0.8);
				color: #FFFFFF;
				border: 0;
				padding: 5px 15px;
				border-radius: 5px;
			}
		</style>
    </head>
    <body>
		<div id="contanter"></div>
		<div class="addEntities">
			<button onclick="showRain()">降雨</button>
			<button onclick="removeStage()">停止降雨</button>
		</div>
		<script>
			var viewer = new Cesium.Viewer("contanter",{
					animation: false,  //是否显示动画控件
		            baseLayerPicker: false, //是否显示图层选择控件
		            geocoder: true, //是否显示地名查找控件
		            timeline: false, //是否显示时间线控件
		            sceneModePicker: true, //是否显示投影方式控件
		            navigationHelpButton: false, //是否显示帮助信息控件
		            infoBox: true,  //是否显示点击要素之后显示的信息
				})
				
			var lat = 42.006;
			var lon = 128.055;
			//取消双击事件
			viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
			//设置homebutton的位置
			Cesium.Camera.DEFAULT_VIEW_RECTANGLE =
				Cesium.Rectangle.fromDegrees(lon - 1, lat - 1, lon + 1, lat + 1); //Rectangle(west, south, east, north)
			//设置初始位置
			viewer.camera.setView({
				destination: Cesium.Cartesian3.fromDegrees(lon, lat, 300000)
			});
			//定义下雨场景 着色器
			function getRainShader() {
				return `uniform sampler2D colorTexture;\n\
							varying vec2 v_textureCoordinates;\n\
						\n\
							float hash(float x){\n\
								return fract(sin(x*133.3)*13.13);\n\
						}\n\
						\n\
						void main(void){\n\
						\n\
							float time = czm_frameNumber / 60.0;\n\
						vec2 resolution = czm_viewport.zw;\n\
						\n\
						vec2 uv=(gl_FragCoord.xy*2.-resolution.xy)/min(resolution.x,resolution.y);\n\
						vec3 c=vec3(.6,.7,.8);\n\
						\n\
						float a=-.4;\n\
						float si=sin(a),co=cos(a);\n\
						uv*=mat2(co,-si,si,co);\n\
						uv*=length(uv+vec2(0,4.9))*.3+1.;\n\
						\n\
						float v=1.-sin(hash(floor(uv.x*100.))*2.);\n\
						float b=clamp(abs(sin(20.*time*v+uv.y*(5./(2.+v))))-.95,0.,1.)*20.;\n\
						c*=v*b; \n\
						\n\
						gl_FragColor = mix(texture2D(colorTexture, v_textureCoordinates), vec4(c,1), 0.5);  \n\
						}\n\
					`;
			}
			// 更改天空的颜色
			function changeSkyStyle(){
				viewer.scene.skyAtmosphere.hueShift = -0.8;
				viewer.scene.skyAtmosphere.saturationShift = -0.7;
				viewer.scene.skyAtmosphere.brightnessShift = -0.33;
				viewer.scene.fog.density = 0.001;
				viewer.scene.fog.minimumBrightness = 0.8;
			}
			
		    // 显示降雨
			var lastStage = null
			function showRain() {
				removeStage();
				var e = new Cesium.PostProcessStage({
						name: "czm_rain",
						fragmentShader: getRainShader()
				});
				viewer.scene.postProcessStages.add(e); 
				lastStage = e
			}
			
			// 移除降雨
			function removeStage() {
				if(lastStage){
					viewer.scene.postProcessStages.remove(lastStage);
					lastStage = null
				}
			}

			showRain()
		
		</script>
    </body>
</html>